package com.ybf.user.dal.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ybf.user.dal.entity.AgentDO;
import com.ybf.user.dal.entity.query.AgentQueryDO;
import com.ybf.user.dal.mapper.AgentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Component
public class AgentManager extends ServiceImpl<AgentMapper, AgentDO> {

    @Autowired
    private AgentMapper agentMapper;


    /**
     *
     *
     * @author 向南
     * @date 19:11 2023/7/31
     * @param: type
     **/
    public List<AgentDO> selectByType(Integer type) {
        if (Objects.isNull(type)) {
            return Collections.emptyList();
        }
        return agentMapper.selectList(new LambdaQueryWrapper<AgentDO>().eq(AgentDO::getType, type));
    }

    /**
     * 查询名称
     *
     * @author 向南
     * @date 16:50 2023/8/9
     * @param: name
     **/
    public AgentDO selectByName(String name) {
        if (StringUtils.isEmpty(name)) {
            return null;
        }
        return agentMapper.selectOne(new LambdaQueryWrapper<AgentDO>().eq(AgentDO::getName, name));
    }

    /**
     * 查询信息
     *
     * @author 向南
     * @date 16:52 2023/8/9
     * @param: agentNo
     **/
    public AgentDO selectByAgentNo(String agentNo) {
        if (StringUtils.isEmpty(agentNo)) {
            return null;
        }
        return agentMapper.selectOne(new LambdaQueryWrapper<AgentDO>().eq(AgentDO::getAgentNo, agentNo));
    }

    /**
     * 分页查询
     *
     * @author 向南
     * @date 17:00 2023/8/9
     * @param: agentQueryDO
     **/
    public IPage<AgentDO> selectPage(AgentQueryDO queryDO) {
        return agentMapper.selectPage(queryDO.getPage(), new LambdaQueryWrapper<AgentDO>()
                .like(!StringUtils.isEmpty(queryDO.getName()), AgentDO::getName, queryDO.getName()));
    }

    /**
     * 查询列表
     *
     * @author 向南
     * @date 14:10 2023/8/11
     * @param: menuId
     **/
    public List<AgentDO> selectByMenuId(Long menuId) {
        if (Objects.isNull(menuId)) {
            return Collections.emptyList();
        }
        return agentMapper.selectByMenuId(menuId);
    }
}
